package com.shadow.baiqun.delegate.send.order;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.shadow.ui.recycler.ObjConverter;

import java.util.ArrayList;

/**
 * @author zy
 *         on 2018/6/26
 */
public class OrderDataConverter {

    public ArrayList<OrderEntity> convert(String response) {
        ArrayList<OrderEntity> list = new ArrayList<>();
        try {
            final JSONArray jsonArray = JSONObject.parseObject(response)
                    .getJSONArray("rows");
            final int size = jsonArray.size();
            for (int i = 0; i < size; i++) {
                final JSONObject object = jsonArray.getJSONObject(i);
                OrderEntity orderEntity = new ObjConverter<OrderEntity>().
                        convert(object.toJSONString(), new TypeReference<OrderEntity>() {
                        });
                list.add(orderEntity);
            }

            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

}
